﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CronusModel;

namespace Cronus.ViewModel.Data
{
    public class Activity
    {
        //*** Constants ***//
        //*** Static ***//
        //*** Member Variables ***//
        private CronusData.ActivitiesRow _ActivityRow;

        //*** Properties ***//
        public DateTime StartTime
        {
            get { return _ActivityRow.StartTime; }
            set { _ActivityRow.StartTime = value; }
        }

        public DateTime EndTime
        {
            get { return _ActivityRow.EndTime; }
            set { _ActivityRow.EndTime = value; }
        }

        public TimeSpan Duration
        {
            get { return _ActivityRow.Duration; }
        }

        public Task Task
        {
            get { return GetTask(); }
        }

        internal CronusData DataSet
        {
            get { return (CronusData)_ActivityRow.Table.DataSet; }
        }

        internal CronusData.ActivitiesRow ActivityRow
        {
            get { return _ActivityRow; }
        }

        //*** Events ***//
        //*** Constructors ***//
        internal Activity(CronusData.ActivitiesRow anActivityRow)
        {
            _ActivityRow = anActivityRow;
        }

        public static Activity CreateNewActivity(Task task)
        {
            var activityRow = task.DataSet.Activities.NewActivitiesRow();
            activityRow.StartTime = DateTime.MinValue;
            activityRow.EndTime = DateTime.MaxValue;
            activityRow.TasksRow = task.TasksRow;

            lock (task)
            {
                task.DataSet.Activities.AddActivitiesRow(activityRow);
            }
            return new Activity(activityRow);
        }

        //*** Abstract Methods ***//
        //*** Methods ***//
        private Task GetTask()
        {
            return new Task(_ActivityRow.TasksRow);
        }
    }
}
